<?php
class User_model extends Model {

    function Usel_model()
    {
        // Call the Model constructor
        parent::Model();
    }
    
	function insert_user($data)
	{
		$this->db->insert($this->db->dbprefix.'users', $data);
		return $this->db->insert_id();
	}
	
	function update_user($id, $data)
	{
		$this->db->where('user_id', $id);
		$this->db->update($this->db->dbprefix.'users', $data);
	}
	
	function user_exists($mail)
	{
		$this->db->select('user_id');
		$query = $this->db->where('e_mail',$mail);
		$query = $this->db->get($this->db->dbprefix . 'users');	
		if ($query->num_rows() > 0)
			return TRUE;
		else 
			return FALSE;
	}
	
	function get_user_by_mail($mail)
	{
		$this->db->select($this->db->dbprefix . 'users.*');
		$query = $this->db->where($this->db->dbprefix . 'users.e_mail like \''.$mail.'\'');
		$query = $this->db->get($this->db->dbprefix . 'users');
		$user = $query->result_array();
		return $user[0];		
	}
	
	function get_user_booking($booking_id)
	{
		$this->db->select($this->db->dbprefix . 'users.*');
		$query = $this->db->where($this->db->dbprefix . 'users.user_id = ' . $this->db->dbprefix . 'bookings.user_id');
		$query = $this->db->where($this->db->dbprefix . 'bookings.booking_id = '.$booking_id);
		$query = $this->db->get($this->db->dbprefix . 'users, '.$this->db->dbprefix . 'bookings');
		$user = $query->result_array();
		return $user[0];	
	}

}
?>